/**
 *	单位管理
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-28
 */

package com.framework.Model;

import com.framerock.db.DB;
import com.framerock.db.DBConn;
import com.framerock.baselib.Rock;
import com.framework.ACore.Model;

import java.util.ArrayList;
import java.util.Map;

public class ModelCompany extends Model {

    public ModelCompany(DBConn dbs) {
        super(dbs);
        this.setTable("company");
    }

    public static ModelCompany get(DBConn dbs)
    {
        return new ModelCompany(dbs);
    }

    //读取创建的单位
    public ArrayList<Map<String, String>> companyCreate(String uid)
    {
        ArrayList<Map<String, String>> rows = getAll("`uid`="+uid+"", "id,logo,name,status,num", "`sort`,`id` asc");
        return rows;
    }

    //我加入的单位
    public ArrayList<Map<String, String>> companyJoin(String uid)
    {
        String sql = "SELECT b.`id`,b.`logo`,b.`name`,b.`num`,b.`hmode`,a.`state` FROM `"+ DB.chuliPerfix("usera") +"` a LEFT JOIN `"+ this.tablenameal+"` b on a.`cid`=b.`id` WHERE a.`uid`="+uid+" and b.`status`=1 and a.`status`=1 and a.`state`<=1 ORDER BY b.`sort`,b.`id` asc";
        return this.nDb.getAll(sql);
    }


    //获取单位下所有人员
    public ArrayList<Map<String, String>> companyUsera(String cid, String where)
    {
        String sql = "SELECT a.`id`,a.`name`,a.`deptid`,a.`ranking`,a.`state`,a.`deptname`,a.`uid`,b.`face` FROM `"+ DB.chuliPerfix("usera")+"` a LEFT JOIN `"+ DB.chuliPerfix("users")+"` b on a.`uid`=b.`id` WHERE a.`cid`="+cid+" AND a.`status`=1 AND a.`state`<=1";
        if(!Rock.isEmpt(where))sql+=" AND "+where+"";
        return this.nDb.getAll(sql);
    }

    //获取单位下一个人信息
    public Map<String, String> companyUsero(String cid, String aid)
    {
        Map<String, String> rs = this.XinxiInfo.get(aid);
        if(rs != null)return rs;
        rs = this.nDb.getOne("`"+ DB.chuliPerfix("usera")+"` a LEFT JOIN `"+ DB.chuliPerfix("users")+"` b on a.`uid`=b.`id`", "a.`cid`="+cid+" AND a.`id`="+aid+"", "a.`id`,a.`name`,a.`deptid`,a.`ranking`,a.`state`,a.`deptname`,a.`uid`,b.`face`");
        this.XinxiInfo.put(aid, rs);
        return rs;
    }
}
